package cao.oschina.function.me.notice;

import android.support.v4.view.ViewPager;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import cao.oschina.R;
import cao.oschina.activity.ToolBarActivity;
import hd.util.adapter.pager.BasePagerAdapter;
import hd.util.widget.PagerTabView;

/**
 * notice消息中心
 * <p/>
 * Created by Haidy on 15/4/11.
 */
public class MyNotice extends ToolBarActivity {

    private ViewPager noticePager;
    private List<View> views;
    private NoticeFunction[] noticeFunctions = new NoticeFunction[4];

    /**
     * 初始化界面
     */
    @Override
    protected void initView() {
        configBack();
        setTitle("消息中心");
        setBody(R.layout.my_notice_view);
        noticePager = (ViewPager) view.findViewById(R.id.notice_pager);
        views = new ArrayList<>();
        views.add(View.inflate(app, R.layout.at_me_view, null));
        views.add(View.inflate(app, R.layout.at_me_view, null));
        views.add(View.inflate(app, R.layout.message_view, null));
        views.add(View.inflate(app, R.layout.fans_view, null));
        noticePager.setAdapter(new BasePagerAdapter(views));
        final PagerTabView pagerTabView = (PagerTabView) view.findViewById(R.id.pagerTabView);
        noticePager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            private int pageWidth = app.getScreenWidth();

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                int offsetPixels = position * pageWidth + positionOffsetPixels;
                pagerTabView.scrollBarScrollTo(-offsetPixels / views.size());
            }

            @Override
            public void onPageSelected(int position) {
                if (noticeFunctions[position] == null) {
                    if (position == 1) {
//                        noticeFunctions[position] =
                    } else if (position == 2) {
                        noticeFunctions[position] = new MessageFunction(views.get(position), MyNotice.this);
                    } else if (position == 3) {

                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
        pagerTabView.setOnCheckedChangeListener(new PagerTabView.OnCheckedChangeListener() {
            @Override
            public void onChecked(View view) {
                int index = view.getId() - R.id.me_pager_tab;
                noticePager.setCurrentItem(index);
            }
        });
    }

    /**
     * 初始化数据
     */
    @Override
    protected void initData() {
        noticeFunctions[0] = new AtMeFunction(views.get(0), this);
    }
}
